import Vue from 'vue'
import Router from 'vue-router'

import Home from './components/home.vue'

import Film from './components/film/film.vue'
import Cinema from './components/cinema/cinema.vue'
import My from './components/my/my.vue'
import NowPlaying from './views/film-views/nowplaying/nowplaying.vue'
import ComingSoon from './views/film-views/comesoon/comingSoon.vue'
import movieCinemaPage from './views/film-cinema-views/movieCinemaPage.vue'
import CinemaTicket from './views/cinemaTicket/cinemaTicket'

import cityList from './views/city/city'
import Search from './views/city/search'
import MovieSearch from './views/film-views/movieSearch/search.vue'
import CinemaSearch from './views/cinema-views/cinemaSearch/cinemaSearch.vue'
import DetaliMovie from './views/detaliMovie/detaliMovie.vue'

import Login from './views/login/login.vue'
// 解决路由跳转，拦截报错Uncaught (in promise)
const originalPush = Router.prototype.push
Router.prototype.push = function push (location) {
  return originalPush.call(this, location).catch(err => err)
}

Vue.use(Router)

export default new Router({
  // mode: 'history',
  base: process.env.BASE_URL,
  // eslint-disable-next-line no-sparse-arrays
  routes: [{
    path: '*',
    redirect: '/home/film/nowplaying'
  },
  {
    path: '/home',
    redirect: '/home/film/nowplaying',
    component: Home,
    children: [{
      path: 'film',
      name: 'film',
      redirect: '/home/film/nowplaying',
      component: Film,
      children: [{
        path: 'nowplaying',
        name: 'nowplaying',
        component: NowPlaying
      },
      {
        path: 'comingsoon',
        name: 'comingsoon',
        component: ComingSoon
      }
      ]
    },
    {
      path: 'cinema',
      name: 'cinema',
      component: Cinema
    }
    ]
  },
  {
    path: '/cityList',
    component: cityList
  },
  {
    path: '/citySearch',
    component: Search
  },
  {
    path: '/movieSearch',
    component: MovieSearch
  }, 
  {
    path: '/cinemaSearch',
    component: CinemaSearch
  },
  {
    path: '/movieCinemaPage',
    component: movieCinemaPage
  },
  {
    path: '/cinemaTicket',
    component: CinemaTicket
  },
  {
    path: '/detailmovie/:id',
    component: DetaliMovie
  },
  {
    path: '/login',
    name: 'login',
    component: Login
  },
  {
    path: '/my',
    name: 'my',
    component: My
  }
  ]
})
